#include "particleEngine.h"

particle::particle(float x, float y, float z, int life)
{
	this->xVel = randfloat(-.005, .005);
	this->yVel = .01;
	this->zVel = randfloat(-.005, .005);
	this->life = life;
	this->e = new entity(1,1);
	this->e->setPosition(x,y,z);
}

particle::~particle()
{
	delete e; //delete the entity
}
void particle::update()
{
	e->translate(xVel, yVel, zVel);
	draw();
}

void particle::draw()
{
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glColor4f(0.4f,0.4f,0.4f,.04f);
	TM()->setTexture("black.png");
	e->display();
}

void particle::lifeHandle()
{
	life--;
}
int particle::getLife() { return life; }

emitter::emitter()
{


}

void emitter::update()
{
	particle* p = new particle(10,0,1,200);
	particleList.push_back(p);

	
	for (std::vector<particle*>::iterator it = particleList.begin(); it!=particleList.end(); ++it)
	{
		(*it)->update();
		(*it)->lifeHandle();
		if((*it)->getLife() <= 0)
		{
			delete (*it);
			it = particleList.erase(it);
		}
	}
}